<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="../../../../lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.useso.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="../../../../lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="../../../../css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="../../../../images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="../../../../images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="../../../../images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="../../../../images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="k8s集群搭建,">










<meta name="description" content="序- 此次部署是在上篇博文中搭建的K8S集群基础之上进行的，涉及使用到的容器已经推到Dockerhub代码、文件：https://github.com/guomaoqiu/flask_kubernetes 逻辑流程图 初始配置1.创建一个namespace 供此次部署使用[root@linux-node1 ~]# kubectl create namespace flask-app-extions">
<meta name="keywords" content="k8s集群搭建">
<meta property="og:type" content="article">
<meta property="og:title" content="Flask App for Kubernetes">
<meta property="og:url" content="http://demo_demo.gitee.io/2018/06/27/flask-app-for-kubernetes/index.html">
<meta property="og:site_name" content="运维人">
<meta property="og:description" content="序- 此次部署是在上篇博文中搭建的K8S集群基础之上进行的，涉及使用到的容器已经推到Dockerhub代码、文件：https://github.com/guomaoqiu/flask_kubernetes 逻辑流程图 初始配置1.创建一个namespace 供此次部署使用[root@linux-node1 ~]# kubectl create namespace flask-app-extions">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15302459587264.jpg?raw=true">
<meta property="og:image" content="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15300742642956.jpg?raw=true">
<meta property="og:image" content="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15302385275244.jpg?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2018/07/15306724015934.jpg">
<meta property="og:image" content="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15302383360947.jpg?raw=true">
<meta property="og:image" content="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15302375026023.jpg?raw=true">
<meta property="og:image" content="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15301582604316.jpg?raw=true">
<meta property="og:updated_time" content="2018-12-10T10:28:44.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Flask App for Kubernetes">
<meta name="twitter:description" content="序- 此次部署是在上篇博文中搭建的K8S集群基础之上进行的，涉及使用到的容器已经推到Dockerhub代码、文件：https://github.com/guomaoqiu/flask_kubernetes 逻辑流程图 初始配置1.创建一个namespace 供此次部署使用[root@linux-node1 ~]# kubectl create namespace flask-app-extions">
<meta name="twitter:image" content="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15302459587264.jpg?raw=true">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://demo_demo.gitee.io/2018/06/27/flask-app-for-kubernetes/">





  <title>Flask App for Kubernetes | 运维人</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/guomaoqiu" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#FD6C6C; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">运维人</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">生命在于折腾</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://demo_demo.gitee.io">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OutMan">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="运维人">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Flask App for Kubernetes</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-27T10:25:20+08:00">
                2018-06-27
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="../../../../categories/Docker/" itemprop="url" rel="index">
                    <span itemprop="name">Docker</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="../../../../categories/Docker/虚拟化-amp-云计算-amp-大数据/" itemprop="url" rel="index">
                    <span itemprop="name">虚拟化&amp;云计算&amp;大数据</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>序<br>-</p>
<p>此次部署是在上篇博文中搭建的K8S集群基础之上进行的，涉及使用到的容器已经推到Dockerhub<br>代码、文件：<a href="https://github.com/guomaoqiu/flask_kubernetes" target="_blank" rel="noopener">https://github.com/guomaoqiu/flask_kubernetes</a></p>
<h2 id="逻辑流程图"><a href="#逻辑流程图" class="headerlink" title="逻辑流程图"></a>逻辑流程图</h2><p><img src="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15302459587264.jpg?raw=true" alt=""></p>
<h2 id="初始配置"><a href="#初始配置" class="headerlink" title="初始配置"></a>初始配置</h2><h5 id="1-创建一个namespace-供此次部署使用"><a href="#1-创建一个namespace-供此次部署使用" class="headerlink" title="1.创建一个namespace 供此次部署使用"></a>1.创建一个namespace 供此次部署使用</h5><pre><code>[root@linux-node1 ~]# kubectl create namespace flask-app-extions-stage
[root@linux-node1 ~]# kubectl get ns
NAME                      STATUS    AGE
default                   Active    29d
flask-app-extions-stage   Active    1m
kube-public               Active    29d
kube-system               Active    29d
</code></pre><h5 id="1-创建用NFS存储目录"><a href="#1-创建用NFS存储目录" class="headerlink" title="1. 创建用NFS存储目录"></a>1. 创建用NFS存储目录</h5><pre><code># 用于flask-app代码存放目录，当pod启动时通过NFS的方式挂载进去
[root@linux-node1 ~]# mkdir /data/flask-app-data
# 用于flask的mysql数据存放目录，当pod启动时通过NFS挂载进去
[root@linux-node1 ~]# mkdir /data/flask-app-db
</code></pre><h5 id="2-安装NFS-Server-略"><a href="#2-安装NFS-Server-略" class="headerlink" title="2. 安装NFS Server(略)"></a>2. 安装NFS Server(略)</h5><h5 id="3-写入配置"><a href="#3-写入配置" class="headerlink" title="3. 写入配置"></a>3. 写入配置</h5><pre><code>[root@linux-node1 ~]# echo &quot;/data/flask-app-db *(rw,sync,no_subtree_check,no_root_squash)&quot; &gt; /etc/exports
[root@linux-node1 ~]# echo &quot;/data/flask-app-data *(rw,sync,no_subtree_check,no_root_squash)&quot; &gt;&gt; /etc/exports
</code></pre><h5 id="4-重启验证"><a href="#4-重启验证" class="headerlink" title="4.重启验证"></a>4.重启验证</h5><pre><code>[root@linux-node1 ~]# systemctl restart nfs-server
[root@linux-node1 ~]# exportfs
# mysql data
/data/flask-app-db
# flask app code
/data/flask-app-data
</code></pre><h5 id="5-创建flask-app使用的pv及pvc"><a href="#5-创建flask-app使用的pv及pvc" class="headerlink" title="5.创建flask-app使用的pv及pvc"></a>5.创建flask-app使用的pv及pvc</h5><pre><code>[root@linux-node1 ~]# kubectl create -f flask_kubernetes/flask-app/flask_app_data_pv.yaml
persistentvolume &quot;flask-app-data-pv&quot; created
[root@linux-node1 ~]# kubectl create -f flask_kubernetes/flask-app/flask_app_data_pvc.yaml
persistentvolumeclaim &quot;flask-app-data-pv-claim&quot; created
</code></pre><h5 id="6-创建flask-app-db使用的pv及pvc"><a href="#6-创建flask-app-db使用的pv及pvc" class="headerlink" title="6.创建flask-app-db使用的pv及pvc"></a>6.创建flask-app-db使用的pv及pvc</h5><pre><code>[root@linux-node1 ~]# kubectl create -f flask_kubernetes/flask_app_db/flask_app_db_pv.yaml
persistentvolume &quot;flask-app-db-pv&quot; created
[root@linux-node1 ~]# kubectl create -f flask_kubernetes/flask_app_db/flask_app_db_pvc.yaml
persistentvolumeclaim &quot;flask-app-db-pv-claim&quot; created
[root@linux-node1 ~]# kubectl get pv -n flask-app-extions-stage
NAME                CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS    CLAIM                                             STORAGECLASS   REASON    AGE
flask-app-data-pv   5Gi        RWO            Recycle          Bound     flask-app-extions-stage/flask-app-data-pv-claim                            5m
flask-app-db-pv     5Gi        RWO            Recycle          Bound     flask-app-extions-stage/flask-app-db-pv-claim                              26s
[root@linux-node1 ~]# kubectl get pvc -n flask-app-extions-stage
NAME                      STATUS    VOLUME              CAPACITY   ACCESS MODES   STORAGECLASS   AGE
flask-app-data-pv-claim   Bound     flask-app-data-pv   5Gi        RWO                           4m
flask-app-db-pv-claim     Bound     flask-app-db-pv     5Gi        RWO                           28s
[root@linux-node1 ~]#
</code></pre><h2 id="部署-flask-app-db"><a href="#部署-flask-app-db" class="headerlink" title="部署 flask-app-db"></a>部署 flask-app-db</h2><p>运行flask交互数据的数据库使用的是mysql，上面我已经创建了用于基于NFS存储mysql数据的持久存储目录 /data/flask-app-db</p>
<h4 id="1-创建配置-MySQL-密码的-Secret"><a href="#1-创建配置-MySQL-密码的-Secret" class="headerlink" title="1. 创建配置 MySQL 密码的 Secret"></a>1. 创建配置 MySQL 密码的 Secret</h4><pre><code>[root@linux-node1 ~]# kubectl create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD
[root@linux-node1 ~]# kubectl  get secret -n flask-app-extions-stage
NAME                  TYPE                                  DATA      AGE
default-token-fr2sg   kubernetes.io/service-account-token   3         47m
mysql-pass            Opaque                                1         14s
</code></pre><h4 id="2-部署-MySQL："><a href="#2-部署-MySQL：" class="headerlink" title="2. 部署 MySQL："></a>2. 部署 MySQL：</h4><pre><code>[root@linux-node1 ~]# kubectl create -f flask_kubernetes/flask_app_db/flask_app_db_deploy.yaml
deployment.apps &quot;flask-app-db&quot; created
[root@linux-node1 ~]# kubectl create -f flask_kubernetes/flask_app_db/flask_app_db_service.yaml
service &quot;flask-app-db&quot; created

# 查看状态
NAME                                   READY     STATUS    RESTARTS   AGE       IP            NODE
pod/flask-app-db-6f55458666-h2dk7      1/1       Running   1          22h       10.2.15.108   192.168.56.12
NAME                      TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE       SELECTOR
service/flask-app-db      NodePort    10.1.68.29     &lt;none&gt;        3306:30006/TCP   22h       app=flask-app-db
NAME                                    DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES                         SELECTOR
deployment.extensions/flask-app-db      1         1         1            1           22h       mysql        mysql:5.6                      app=flask-app-db,tier=mysql

# 以上可以知道该pod运行在节点192.168.56.12上面，我这里使用的是NodePort方式，然后映射了一个30006端口出来到节点上面

# 可以尝试登陆测试
[root@linux-node1 flask_app_db]# mysql -uroot -pdevopsdemo -h192.168.56.12 -P 30006
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type &apos;help;&apos; or &apos;\h&apos; for help. Type &apos;\c&apos; to clear the current input statement.

MySQL [(none)]&gt; show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.02 sec)

MySQL [(none)]&gt;

# 顺便我们在这里手动创建一下flask-app需要用到的数据库 devopsdemo, 因为在flask-app在启动过程中需要去初始化数据库并创建数据表。
MySQL [(none)]&gt; CREATE DATABASE devopsdemo;
Query OK, 1 row affected (0.01 sec)

#数据库目录,可以看到mysql数据已经通过nfs的方式存储到了我们nfs server所在主机映射出去的目录
[root@linux-node1 ~]# tree /data/flask-app-db/ -L 1
/data/flask-app-db/
├── auto.cnf
├── devopsdemo
├── ibdata1
├── ib_logfile0
├── ib_logfile1
├── mysql
└── performance_schema

3 directories, 4 files
</code></pre><h2 id="部署flask-app"><a href="#部署flask-app" class="headerlink" title="部署flask-app"></a>部署flask-app</h2><h4 id="1-将flask程序代码放到-data-flask-app-data"><a href="#1-将flask程序代码放到-data-flask-app-data" class="headerlink" title="1.将flask程序代码放到/data/flask-app-data/"></a>1.将flask程序代码放到/data/flask-app-data/</h4><pre><code>[root@linux-node1 ~]# cp -rf flask_app_code/* /data/flask-app-data/
[root@linux-node1 ~]# tree /data/flask-app-data/ -L 1
/data/flask-app-data/
├── app
├── config.py
├── flask_uwsgi.ini
├── LICENSE
├── manage.py
├── README.md
├── requirements.txt
├── screenshots
├── supervisord.conf
└── tests

3 directories, 9 files
</code></pre><h4 id="2-修改flask程序连接数据库的配置信息"><a href="#2-修改flask程序连接数据库的配置信息" class="headerlink" title="2. 修改flask程序连接数据库的配置信息"></a>2. 修改flask程序连接数据库的配置信息</h4><pre><code>[root@linux-node1 ~]# vim /data/flask-app-data/config.py
......
......
    db_host = &apos;flask-app-db&apos; # 在pod启动过程中会去加载k8s的环境变量；这个flask-app-db 就是mysql的svc
    db_user = &apos;root&apos;         # 默认为root
    db_pass = &quot;devopsdemo&quot;   # 数据库密码
    db_name = &apos;devopsdemo&apos;   # 数据库名称
......
......
</code></pre><h4 id="3-部署flask-app"><a href="#3-部署flask-app" class="headerlink" title="3. 部署flask-app"></a>3. 部署flask-app</h4><pre><code>[root@linux-node1 ~]# kubectl create -f flask_kubernetes/flask_app/flask_app_deployment.yaml
deployment.apps &quot;flask-app&quot; created
[root@linux-node1 ~]# kubectl create -f flask_kubernetes/flask_app/flask_app_service.yaml
service &quot;flask-app&quot; created

# 查看状态:
[root@linux-node1 ~]# kubectl get pod,svc,deployment,rc -o wide   -n flask-app-extions-stage
NAME                                   READY     STATUS    RESTARTS   AGE       IP            NODE
pod/flask-app-65646687ff-4gg7g         1/1       Running   0          17h       10.2.42.125   192.168.56.13
pod/flask-app-65646687ff-7d5g6         1/1       Running   0          17h       10.2.42.124   192.168.56.13
pod/flask-app-65646687ff-xkq6k         1/1       Running   0          17h       10.2.42.123   192.168.56.13
pod/flask-app-db-6f55458666-h2dk7      1/1       Running   1          22h       10.2.15.108   192.168.56.12

NAME                      TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE       SELECTOR
service/flask-app         ClusterIP   10.1.173.169   &lt;none&gt;        3032/TCP         22h       app=flask-app
service/flask-app-db      NodePort    10.1.68.29     &lt;none&gt;        3306:30006/TCP   22h       app=flask-app-db

NAME                                    DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES                         SELECTOR
deployment.extensions/flask-app         3         3         3            3           22h       flask-app    guomaoqiu/python27baseenv:v2   app=flask-app,tier=frontend
deployment.extensions/flask-app-db      1         1         1            1           22h       mysql        mysql:5.6                      app=flask-app-db,tier=mysql


# 以上可知 我的flask-app运行了三个副本；
# 并且采用的是ClusterIP Type,3032是flask+supervisor+uwsgi 之后 uwsgsi 暴露出来的二端口
# 此时我们访问是没有用的；因为uwgsi需要结合用到Nginx来访问；于是我下面将会部署nginx ---&gt; uwgsi(flask-app)
</code></pre><hr>
<h2 id="部署flask-app-nginx"><a href="#部署flask-app-nginx" class="headerlink" title="部署flask-app-nginx"></a>部署flask-app-nginx</h2><p>因为这个nginx的配置我这里需要修改做一些定制方面的配置，所以有一个将单个配置文件挂载到pod里面的需求；于是这里使用到了k8s的ConfigMap功能</p>
<h4 id="1-找到需要挂载进pod的nginx配置文件"><a href="#1-找到需要挂载进pod的nginx配置文件" class="headerlink" title="1. 找到需要挂载进pod的nginx配置文件:"></a>1. 找到需要挂载进pod的nginx配置文件:</h4><pre><code>[root@linux-node1 ~]# kubectl create  configmap nginx-conf --from-file=/root/flask_kubernetes/flask_app_nginx/nginx.conf -n  flask-app-extions-stage
[root@linux-node1 ~]# kubectl get configmap -n flask-app-extions-stage
NAME         DATA      AGE
nginx-conf   1         11s
# 通过describe就可以看到这个conf的详细内容，其实就在我们nginx.conf配置文件的基础上加上了k8s一些特有的属性值
[root@linux-node1 ~]# kubectl describe configmap/nginx-conf -n flask-app-extions-stage
</code></pre><h4 id="2-部署flask-app-nginx"><a href="#2-部署flask-app-nginx" class="headerlink" title="2.部署flask-app-nginx"></a>2.部署flask-app-nginx</h4><pre><code>[root@linux-node1 flask_app_nginx]# kubectl create -f flask_app_nginx_deploy.yaml
deployment.apps &quot;flask-app-nginx&quot; created
[root@linux-node1 flask_app_nginx]# kubectl create -f flask_app_nginx_service.yaml
service &quot;flask-app-nginx&quot; created

# 查看状态：
[root@linux-node1 ~]# kubectl get pod,svc,deployment,rc -o wide   -n flask-app-extions-stage
NAME                                   READY     STATUS    RESTARTS   AGE       IP            NODE
pod/flask-app-65646687ff-4gg7g         1/1       Running   0          17h       10.2.42.125   192.168.56.13
pod/flask-app-65646687ff-7d5g6         1/1       Running   0          17h       10.2.42.124   192.168.56.13
pod/flask-app-65646687ff-xkq6k         1/1       Running   0          17h       10.2.42.123   192.168.56.13
pod/flask-app-db-6f55458666-h2dk7      1/1       Running   1          22h       10.2.15.108   192.168.56.12
pod/flask-app-nginx-657fd4c57c-p6qdx   1/1       Running   12         18h       10.2.42.119   192.168.56.13
pod/flask-app-nginx-657fd4c57c-v4qsp   1/1       Running   12         18h       10.2.42.117   192.168.56.13
pod/flask-app-nginx-657fd4c57c-xtpmm   1/1       Running   12         18h       10.2.42.118   192.168.56.13

NAME                      TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE       SELECTOR
service/flask-app         ClusterIP   10.1.173.169   &lt;none&gt;        3032/TCP         22h       app=flask-app
service/flask-app-db      NodePort    10.1.68.29     &lt;none&gt;        3306:30006/TCP   22h       app=flask-app-db
service/flask-app-nginx   ClusterIP   10.1.193.82    &lt;none&gt;        80/TCP           21h       app=flask-app-nginx

NAME                                    DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES                         SELECTOR
deployment.extensions/flask-app         3         3         3            3           22h       flask-app    guomaoqiu/python27baseenv:v2   app=flask-app,tier=frontend
deployment.extensions/flask-app-db      1         1         1            1           22h       mysql        mysql:5.6                      app=flask-app-db,tier=mysql
deployment.extensions/flask-app-nginx   3         3         3            3           21h       nginx        nginx:latest                   app=flask-app-nginx

# 以上 运行了三个flak-app-nginx ,采用的是ClusterIP Type
# 访问验证,直接访问的是flask-app-nginx 的VIP(ClusterIP)
[root@linux-node1 ~]# curl -I 10.1.193.82/auth/login
HTTP/1.1 200 OK
Server: nginx/1.15.0
Date: Wed, 27 Jun 2018 04:35:12 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 4026
Connection: keep-alive
Set-Cookie: session=eyJjc3JmX3Rva2VuIjp7IiBiIjoiT0RrNVpXUmpZV014T1daalkyUmlOamRsWXpBNVpqUTVZMk0wTkRnMU9ERm1NVFUzTURrME5BPT0ifX0.DhSlgA.Biu7EYC7qfj4x8--HlR8VUZFUgk; HttpOnly; Path=/
</code></pre><p>以上说明我们能够成功的访问到我们的flask-app服务啦,在用linux 终端下的w3m <a href="http://10.1.193.82/auth/login" target="_blank" rel="noopener">http://10.1.193.82/auth/login</a> 访问一下呢，说明也是没问题的；那后端uwgsi or flask-app or flask-nginx的访问日志此时毋庸置疑是已经有了的。<br><img src="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15300742642956.jpg?raw=true" alt=""></p>
<p>那问题来了；此时我只是在集群内部能够访问，那如何在外面访问呢？那就主要将flask_nginx_service.yaml中的Type该为nodePort,然后从新部署一下flask_app_nginx_services</p>
<pre><code>[root@linux-node1 ~]# more /root/flask_kubernetes/flask_app_nginx/flask_app_nginx_service.yaml
kind: Service
apiVersion: v1
metadata:
  name: flask-app-nginx
  namespace: flask-app-extions-stage
spec:
  type: NodePort
  selector:
    app: flask-app-nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 30001
  selector:
    app: flask-app-nginx

[root@linux-node1 ~]# kubectl describe svc/flask-app-nginx -n flask-app-extions-stage
Name:              flask-app-nginx
Namespace:         flask-app-extions-stage
Labels:            &lt;none&gt;
Annotations:       &lt;none&gt;
Selector:          app=flask-app-nginx
Type:              ClusterIP
IP:                10.1.193.82
Port:              &lt;unset&gt;  80/TCP
TargetPort:        80/TCP
Endpoints:         10.2.42.117:80,10.2.42.118:80,10.2.42.119:80
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre><p>此时如果是外网访问就应该是NodeIP+nodePort啦：<br><img src="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15302385275244.jpg?raw=true" alt=""></p>
<p>但是这种方式并不是很理想；本来就是要让他直接访问80 port的，于是采用另外一种暴露端口的方式——Ingress</p>
<p>（这里我还是把flask-app-nginx的service改回了ClusterIP)</p>
<hr>
<h2 id="部署-Ingress-Nginx"><a href="#部署-Ingress-Nginx" class="headerlink" title="部署 Ingress-Nginx"></a>部署 Ingress-Nginx</h2><p>Ingress 使用开源的反向代理负载均衡器来实现对外暴漏服务，比如 Nginx、Apache、Haproxy等。Nginx Ingress 一般有三个组件组成：</p>
<ul>
<li>Nginx 反向代理负载均衡器</li>
<li>Ingress Controller 可以理解为控制器，它通过不断的跟 Kubernetes API 交互，实时获取后端 Service、Pod 等的变化，比如新增、删除等，然后结合 Ingress 定义的规则生成配置，然后动态更新上边的 Nginx 负载均衡器，并刷新使配置生效，来达到服务自动发现的作用。</li>
<li>Ingress 则是定义规则，通过它定义某个域名的请求过来之后转发到集群中指定的 Service。它可以通过 Yaml 文件定义，可以给一个或多个 Service 定义一个或多个 Ingress 规则。</li>
</ul>
<h4 id="1-获取官方提供的yaml"><a href="#1-获取官方提供的yaml" class="headerlink" title="1.获取官方提供的yaml"></a>1.获取官方提供的yaml</h4><pre><code>[root@linux-node1 ~]# cd flask_8s &amp;&amp;  git clone https://github.com/kubernetes/ingress-nginx.git
[root@linux-node1 ~]# tree flask_8s/ingress-nginx/
flask_8s/ingress-nginx/
├── configmap.yaml               :提供configmap可以在线更行nginx的配置
├── default-backend.yaml         :提供一个缺省的后台错误页面 404
├── mandatory.yaml               :这个文件包含了这个目录下面所有yaml的内容，可以不用
├── namespace.yaml               :创建一个独立的命名空间 ingress-nginx
├── rbac.yaml                      :创建对应的role rolebinding 用于rbac
├── tcp-services-configmap.yaml  :修改L4负载均衡配置的configmap
├── udp-services-configmap.yaml  :修改L4负载均衡配置的configmap
└── with-rbac.yaml               :有应用rbac的nginx-ingress-controller组件   

0 directories, 8 files
</code></pre><h4 id="2-修改官方的配置"><a href="#2-修改官方的配置" class="headerlink" title="2.修改官方的配置"></a>2.修改官方的配置</h4><ol>
<li><p>hostNetwork: true：添加该字段，暴露nginx-ingress-controller pod的服务端口（80）</p>
</li>
<li><p>nodeSelector: 增加亲和性部署，有custom/ingress-controller-ready 标签的节点才会部署该DaemonSet</p>
</li>
<li><p>kind: DaemonSet：官方原始文件使用的是deployment，replicate 为 1，这样将会在某一台节点上启动对应的nginx-ingress-controller pod。外部流量访问至该节点，由该节点负载分担至内部的service。测试环境考虑防止单点故障，改为DaemonSet然后删掉replicate ，配合亲和性部署在制定节点上启动nginx-ingress-controller pod，确保有多个节点启动nginx-ingress-controller pod，后续将这些节点加入到外部硬件负载均衡组实现高可用性。</p>
<p>DaemonSet 确保全部（或者某些）节点上运行一个 Pod 的副本。当有节点加入集群时，也会为他们新增一个 Pod 。 当有节点从集群移除时，这些 Pod 也会被回收。删除 DaemonSet 将会删除它创建的所有 Pod。</p>
<p>使用 DaemonSet 的一些典型用法：</p>
<ul>
<li>运行集群存储 daemon，例如在每个节点上运行 glusterd、ceph。</li>
<li>在每个节点上运行日志收集 daemon，例如fluentd、logstash。</li>
<li>在每个节点上运行监控 daemon，例如 Prometheus Node Exporter、collectd、Datadog 代理、New Relic 代理，或 Ganglia gmond。</li>
</ul>
<p>个人理解就是，daemonset更具有定制性，用这种方式默认会在每个节点都运行一个副本；除非配置亲和性，让其运行在某个或某几个特定的节点上。如果用这种方式部署的，在查看详情时他的资源名称为简写的 <code>ds</code>, 两种方式的显示结果：</p>
</li>
</ol>
<p><img src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/2018/07/15306724015934.jpg" alt="">￼</p>
<h4 id="3-为需要部署nginx-ingress-controller的节点设置lable"><a href="#3-为需要部署nginx-ingress-controller的节点设置lable" class="headerlink" title="3.为需要部署nginx-ingress-controller的节点设置lable"></a>3.为需要部署nginx-ingress-controller的节点设置lable</h4><pre><code>[root@linux-node1 ~]# kubectl label nodes 192.168.56.12 custom/ingress-controller-ready=true
[root@linux-node1 ~]# kubectl label nodes 192.168.56.13 custom/ingress-controller-ready=true
[root@linux-node1 ~]# kubectl get nodes --show-labels
NAME            STATUS    ROLES     AGE       VERSION   LABELS
192.168.56.12   Ready     &lt;none&gt;    28d       v1.10.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,custom/ingress-controller-ready=true,kubernetes.io/hostname=192.168.56.12
192.168.56.13   Ready     &lt;none&gt;    27d       v1.10.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,custom/ingress-controller-ready=true,kubernetes.io/hostname=192.168.56.13

# 以上，因为我这里就两个计算节点；所以都打上custom/ingress-controller-ready=true这个标签
</code></pre><h4 id="4-执行创建yaml文件"><a href="#4-执行创建yaml文件" class="headerlink" title="4.执行创建yaml文件:"></a>4.执行创建yaml文件:</h4><pre><code>[root@linux-node1 ~]# kubectl create -f namespace.yaml
[root@linux-node1 ~]# kubectl create -f default-backend.yaml
[root@linux-node1 ~]# kubectl create -f configmap.yaml
[root@linux-node1 ~]# kubectl create -f tcp-services-configmap.yaml
[root@linux-node1 ~]# kubectl create -f udp-services-configmap.yaml
[root@linux-node1 ~]# kubectl create -f rbac.yaml
[root@linux-node1 ~]# kubectl create -f with-rbac.yaml
</code></pre><h4 id="5-查看创建状态："><a href="#5-查看创建状态：" class="headerlink" title="5.查看创建状态："></a>5.查看创建状态：</h4><p>创建过程会去拉镜像比较慢，可能会不成功，前面说过那都是因为`%#@%￥#@·的原因，<br>所以还是记得给docker一把梯子。</p>
<pre><code>[root@linux-node1 ~]# kubectl get pod,svc,deployment,rc -o wide   -n ingress-nginx
NAME                                       READY     STATUS    RESTARTS   AGE       IP              NODE
pod/default-http-backend-5c6d95c48-dwl56   1/1       Running   0          16h       10.2.42.130     192.168.56.13
pod/nginx-ingress-controller-55trv         1/1       Running   0          15h       192.168.56.12   192.168.56.12
pod/nginx-ingress-controller-58nf4         1/1       Running   0          15h       192.168.56.13   192.168.56.13

NAME                           TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE       SELECTOR
service/default-http-backend   ClusterIP   10.1.89.141   &lt;none&gt;        80/TCP    16h       app=default-http-backend

NAME                                         DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS             IMAGES                                        SELECTOR
deployment.extensions/default-http-backend   1         1         1            1           16h       default-http-backend   gcr.io/google_containers/defaultbackend:1.4   app=default-http-backend


# 以上可以看到nginx-ingress-controller已经成功运行在了这两个打了标签的节点上面
</code></pre><p>此时只是把ingress给搭建好，如果要用得根据实际情况写转发规则了，当前我们的目的是通过它定义某个域名的请求过来之后转发到集群中指定的 Service，即此次部署的 <code>flask-app-nginx</code></p>
<h4 id="6-创建规则："><a href="#6-创建规则：" class="headerlink" title="6.创建规则："></a>6.创建规则：</h4><pre><code>[root@linux-node1 ingress-nginx]# cat &gt; test.ingress.yaml &lt; EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
    namespace: flask-app-extions-stage
spec:
  rules:
  - host: test.flaskapp.ingress
    http:
      paths:
      - path: /
        backend:
          serviceName: flask-app-nginx
          servicePort: 80
EOF
// host: 对应的域名 
// path: url上下文 
// backend:后向转发 到对应的 serviceName: servicePort:

[root@linux-node1 ingress-nginx]# kubectl apply -f test-ingress.yaml
[root@linux-node1 ingress-nginx]# kubectl get ingress -n flask-app-extions-stage
NAME           HOSTS                   ADDRESS   PORTS     AGE
test-ingress   test.flaskapp.ingress             80        15h
[root@linux-node1 ingress-nginx]# kubectl describe ingress/test-ingress -n flask-app-extions-stage
Name:             test-ingress
Namespace:        flask-app-extions-stage
Address:
Default backend:  default-http-backend:80 (&lt;none&gt;)
Rules:
  Host                   Path  Backends
  ----                   ----  --------
  test.flaskapp.ingress
                         /   flask-app-nginx:80 (&lt;none&gt;)
Annotations:
Events:
  Type    Reason  Age   From                      Message
  ----    ------  ----  ----                      -------
  Normal  CREATE  15h   nginx-ingress-controller  Ingress flask-app-extions-stage/test-ingress
  Normal  CREATE  15h   nginx-ingress-controller  Ingress flask-app-extions-stage/test-ingress
  Normal  CREATE  15h   nginx-ingress-controller  Ingress flask-app-extions-stage/test-ingress
  Normal  CREATE  15h   nginx-ingress-controller  Ingress flask-app-extions-stage/test-ingress
</code></pre><h4 id="7-测试："><a href="#7-测试：" class="headerlink" title="7.测试："></a>7.测试：</h4><p>既然是通过域名访问，那这里我就在node1上面直接修改hosts的方式然后访问</p>
<pre><code>[root@linux-node1 ~]# echo &quot;192.168.56.12 test.flaskapp.ingress&quot; &gt;&gt; /etc/hosts
[root@linux-node1 ~]# echo &quot;192.168.56.13 test.flaskapp.ingress&quot; &gt;&gt; /etc/hosts

[root@linux-node1 ingress-nginx]# curl -I test.flaskapp.ingress/auth/login
HTTP/1.1 200 OK
Server: nginx/1.13.12
Date: Thu, 28 Jun 2018 02:59:16 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 4030
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: session=eyJjc3JmX3Rva2VuIjp7IiBiIjoiTXpGbFlUWmlOelV4WXpabVlqTXlNVFJpWTJVMk1HWTVObVV5TURRd09HSTNPVFV4WXprd01RPT0ifX0.DhXghA.3HHbX3fvShem9KlkINr8jDGwcSc; HttpOnly; Path=/

# 或者指定模拟的域名:

[root@linux-node1 ingress-nginx]# curl -vI http://192.168.56.12/auth/login -H &apos;host: test.flaskapp.ingress&apos;
* About to connect() to 192.168.56.12 port 80 (#0)
*   Trying 192.168.56.12...
* Connected to 192.168.56.12 (192.168.56.12) port 80 (#0)
&gt; HEAD /auth/login HTTP/1.1
&gt; User-Agent: curl/7.29.0
&gt; Accept: */*
&gt; host: test.flaskapp.ingress
&gt;
&lt; HTTP/1.1 200 OK
HTTP/1.1 200 OK
&lt; Server: nginx/1.13.12
Server: nginx/1.13.12
&lt; Date: Thu, 28 Jun 2018 03:00:21 GMT
Date: Thu, 28 Jun 2018 03:00:21 GMT
&lt; Content-Type: text/html; charset=utf-8
Content-Type: text/html; charset=utf-8
&lt; Content-Length: 4030
Content-Length: 4030
&lt; Connection: keep-alive
Connection: keep-alive
&lt; Vary: Accept-Encoding
Vary: Accept-Encoding
&lt; Set-Cookie: session=eyJjc3JmX3Rva2VuIjp7IiBiIjoiT1RNMVpUWTBZV1V6TkdWaU5EazBZMkl5TmpZMFl6VTNPVFF3TVdaa09UVXpNall3T1RRNE1RPT0ifX0.DhXgxQ.BnjwR-swXvmD-kUGhtlvhpHuUIY; HttpOnly; Path=/
Set-Cookie: session=eyJjc3JmX3Rva2VuIjp7IiBiIjoiT1RNMVpUWTBZV1V6TkdWaU5EazBZMkl5TmpZMFl6VTNPVFF3TVdaa09UVXpNall3T1RRNE1RPT0ifX0.DhXgxQ.BnjwR-swXvmD-kUGhtlvhpHuUIY; HttpOnly; Path=/

&lt;
* Connection #0 to host 192.168.56.12 left intact
</code></pre><p>在外部如果要访问也需要绑定域名到node节点，然后访问<br><img src="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15302383360947.jpg?raw=true" alt=""></p>
<p>ok至此该项目就部署得差不多了，上面flask-app登录，注册正常！<br><img src="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15302375026023.jpg?raw=true" alt=""></p>
<p>那pod如何做到伸缩呢；执行以下命令就行了</p>
<pre><code># 目前我的flask-app是运行了3个，怼20个flask-app应用
[root@linux-node1 ~]# kubectl get deploy/flask-app -n flask-app-extions-stage
NAME        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
flask-app   3         3         3            3           23h
[root@linux-node1 ~]# kubectl scale --replicas=20 deployment.extensions/flask-app -n flask-app-extions-stage
deployment.extensions &quot;flask-app&quot; scaled
[root@linux-node1 ~]# kubectl get deploy/flask-app -n flask-app-extions-stage
NAME        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
flask-app   20        20        20           20          23h
# 所以副本数就是靠deploment中的 replicas 或者 命令行的scale --replicas来控制
</code></pre><hr>
<h3 id="部署总结："><a href="#部署总结：" class="headerlink" title="部署总结："></a>部署总结：</h3><p>坑:<br>在上面我部署好ingress-nginx后，通过访问哪一步报错了；于是去查了 pod/nginx-ingress-controller-58nf4 的日志，错误日志刷屏啊<br><img src="https://github.com/guomaoqiu/flask_kubernetes/blob/master/screenshots/15301582604316.jpg?raw=true" alt=""></p>
<p>官方文档不完整啊，少了创建ingress-services的内容；<br>解决办法：</p>
<pre><code>[root@linux-node1 ingress-nginx]# cat &gt; ingress-nginx-services.yaml &lt; EOF
apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
spec:
  type: NodePort
  ports:
  - name: http
    port: 80
    targetPort: 80
    protocol: TCP
  - name: https
    port: 443
    targetPort: 443
    protocol: TCP
  selector:
    app: ingress-nginx
EOF
[root@linux-node1 ingress-nginx]# kubectl create -f ingress-nginx-services.yaml
</code></pre><p>部署遇到的主要知识点：</p>
<ul>
<li>K8S deployment的yaml文件编写；</li>
<li>K8S 持久化存储NFS方式；配置管理ConfigMap;</li>
<li>K8S 集群中各种端口/IP类型的工作模式以及服务暴露方式；</li>
</ul>
<p>但是如果后端数据结构足够简单 完全可以用sqlite3来存储数据,这里主要是为了学习在k8s中结合mysql跑应用~</p>
<p>by the way: 可能看到我创建的pod等资源的AGE已经是过去十几个小时，这个没关系的；前面创建了之后笔记就停顿了一下。后续才继续写的🍺🍺🍺</p>

      
    </div>
    
    
    
<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>


  
</div>
    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="../../../../tags/k8s集群搭建/" rel="tag"># k8s集群搭建</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="../../18/nginx-uwsgi-flask-supervisord-redis-mysql-docker-e9-83-a8-e7-bd-b2-2/" rel="next" title="Nginx-uWsgi-Flask-Supervisord-Redis-MySQL-Docker 部署">
                <i class="fa fa-chevron-left"></i> Nginx-uWsgi-Flask-Supervisord-Redis-MySQL-Docker 部署
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="../../29/10k8s-ji-qun-da-jianxin-zengnode-jie-dian/" rel="prev" title="10-K8s集群搭建---新增Node节点">
                10-K8s集群搭建---新增Node节点 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png" alt="OutMan">
            
              <p class="site-author-name" itemprop="name">OutMan</p>
              <p class="site-description motion-element" itemprop="description">😊</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="../../../../archives/">
              
                  <span class="site-state-item-count">79</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="../../../../categories/index.html">
                  <span class="site-state-item-count">22</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="../../../../tags/index.html">
                  <span class="site-state-item-count">46</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/guomaoqiu" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i></a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:guomaoqiu@google.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i></a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#逻辑流程图"><span class="nav-number">1.</span> <span class="nav-text">逻辑流程图</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#初始配置"><span class="nav-number">2.</span> <span class="nav-text">初始配置</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-创建一个namespace-供此次部署使用"><span class="nav-number">2.0.0.1.</span> <span class="nav-text">1.创建一个namespace 供此次部署使用</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#1-创建用NFS存储目录"><span class="nav-number">2.0.0.2.</span> <span class="nav-text">1. 创建用NFS存储目录</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-安装NFS-Server-略"><span class="nav-number">2.0.0.3.</span> <span class="nav-text">2. 安装NFS Server(略)</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-写入配置"><span class="nav-number">2.0.0.4.</span> <span class="nav-text">3. 写入配置</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4-重启验证"><span class="nav-number">2.0.0.5.</span> <span class="nav-text">4.重启验证</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#5-创建flask-app使用的pv及pvc"><span class="nav-number">2.0.0.6.</span> <span class="nav-text">5.创建flask-app使用的pv及pvc</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#6-创建flask-app-db使用的pv及pvc"><span class="nav-number">2.0.0.7.</span> <span class="nav-text">6.创建flask-app-db使用的pv及pvc</span></a></li></ol></li></ol><li class="nav-item nav-level-2"><a class="nav-link" href="#部署-flask-app-db"><span class="nav-number">3.</span> <span class="nav-text">部署 flask-app-db</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-创建配置-MySQL-密码的-Secret"><span class="nav-number">3.0.1.</span> <span class="nav-text">1. 创建配置 MySQL 密码的 Secret</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-部署-MySQL："><span class="nav-number">3.0.2.</span> <span class="nav-text">2. 部署 MySQL：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#部署flask-app"><span class="nav-number">4.</span> <span class="nav-text">部署flask-app</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-将flask程序代码放到-data-flask-app-data"><span class="nav-number">4.0.1.</span> <span class="nav-text">1.将flask程序代码放到/data/flask-app-data/</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-修改flask程序连接数据库的配置信息"><span class="nav-number">4.0.2.</span> <span class="nav-text">2. 修改flask程序连接数据库的配置信息</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-部署flask-app"><span class="nav-number">4.0.3.</span> <span class="nav-text">3. 部署flask-app</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#部署flask-app-nginx"><span class="nav-number">5.</span> <span class="nav-text">部署flask-app-nginx</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-找到需要挂载进pod的nginx配置文件"><span class="nav-number">5.0.1.</span> <span class="nav-text">1. 找到需要挂载进pod的nginx配置文件:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-部署flask-app-nginx"><span class="nav-number">5.0.2.</span> <span class="nav-text">2.部署flask-app-nginx</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#部署-Ingress-Nginx"><span class="nav-number">6.</span> <span class="nav-text">部署 Ingress-Nginx</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-获取官方提供的yaml"><span class="nav-number">6.0.1.</span> <span class="nav-text">1.获取官方提供的yaml</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-修改官方的配置"><span class="nav-number">6.0.2.</span> <span class="nav-text">2.修改官方的配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-为需要部署nginx-ingress-controller的节点设置lable"><span class="nav-number">6.0.3.</span> <span class="nav-text">3.为需要部署nginx-ingress-controller的节点设置lable</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-执行创建yaml文件"><span class="nav-number">6.0.4.</span> <span class="nav-text">4.执行创建yaml文件:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-查看创建状态："><span class="nav-number">6.0.5.</span> <span class="nav-text">5.查看创建状态：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6-创建规则："><span class="nav-number">6.0.6.</span> <span class="nav-text">6.创建规则：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-测试："><span class="nav-number">6.0.7.</span> <span class="nav-text">7.测试：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#部署总结："><span class="nav-number">6.1.</span> <span class="nav-text">部署总结：</span></a></li></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OutMan</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="../../../../lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="../../../../js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="../../../../js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="../../../../js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="../../../../js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="../../../../js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
